package com.di.base.controller;


import com.di.base.service.OrderTblService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (OrderTbl)表控制层
 *
 * @author makejava
 * @since 2025-07-08 22:45:46
 */
@Slf4j
@RestController
@RequestMapping("orderTbl")
public class OrderTblController{

    @Resource
    private OrderTblService orderService;

    /**
     * 创建订单接口（发起全局事务）
     * 请求方式：POST
     * 请求路径：http://localhost:8081/order/create
     * 请求参数：userId、productId、count、amount
     */
    @GetMapping("/create")
    public String createOrder() {
        // 写死参数
        String userId = "U1002";
        String productId = "P10004";
        int count = 2;
//        单价
        Double price = new Double("99.99");
        log.info("收到创建订单请求：userId={}, productId={}, count={}, amount={}", userId, productId, count, price);
        try {
            orderService.createOrder(userId, productId,count, price);
            return "下单成功";
        } catch (Exception e) {
            log.error("下单失败", e);
            return "下单失败";
        }
    }

}

